<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="shortcut icon" href="../imgs/7fa57f35c179bad9cc9f18e2dd9b1d40.ico" />
  <!-- 1. 引入bootstrap.css -->
  <link rel="stylesheet" href="../plugins/bootstrap-3.4.1-dist/css/bootstrap.css">

  <title>『帐号』-登录</title>
  <style>
    body {
      background-image: url(../imgs/login-bg.56a249bc.png);
    }

    #logo {
      -webkit-text-size-adjust: 100%;
      -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
      font-family: Roman-55, Helvetica Neue, Helvetica, Arial, sans-serif;
      font-feature-settings: "salt";
      font-weight: 800;
      list-style: none;
      cursor: pointer;
      fill: currentColor;
      line-height: 1;
      color: #f50514;
      font-size: 20px;
      box-sizing: border-box;
      vertical-align: middle;
    }

    #logo> :first-child+li {
      /* width:200px; */
      display: inline-block;
      padding-top: 15px;

    }

    #dhl li:hover {
      border-bottom: #f50514;
      border-style: solid;
      border-left-width: 0px;
      border-right-width: 0px;
      border-top-width: 0px;
      border-bottom-width: 5px;
    }

    #login_div {
      /* border:1px solid red; */
      margin-top: 80px;
      padding: 30px;
      box-shadow: 2px -2px 6px #ccc;
      border-radius: 10px;
    }

    #user_enter {
      color: #222;
      font-size: 30px;
      text-shadow: 3px 3px 5px rgb(107, 107, 107);
    }

    #a1 {
      padding: 0px;
    }
  </style>
</head>

<body>
  <!-- 导航begin -->
  <div class="container-fluid">
    <!-- 定义一行 -->
    <div class="row">
      <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
          <div class="navbar-header">
            <ul class="nav navbar-nav nav-left" id="logo">
              <li>
                <img src="../imgs/OnePlus_Logo.png" style="width: 50px;height: 50px;" alt="">
              </li>
              <li id="onepluse">ONEPLUSE</li>
            </ul>
          </div>
          <div class="collapse navbar-collapse" id="example-navbar-collapse">

            <ul class="nav navbar-nav navbar-right" id="dhl">
              <li class="active" id="l1"><a href="login.html">登录</a></li>
              <li id="l2"><a href="#">首页</a></li>
              <li id="l3"><a href="#">我的购物车</a></li>
              <li><a href="#" id="Myorder">一加故事</a></li>
              <li><a href="#">安全退出</a></li>
              <li>
                <a id="a1" href="#"><img src="../imgs/OIP-C.jpg" style="width: 50px;height: 50px;border-radius: 50%;"
                    alt=""></a>
              </li>
            </ul>
          </div>
        </div>
      </nav>
    </div>
  </div>
  <!-- 导航end -->

  <!-- 登录begin -->
  <div class="container">
    <div class="row" id="login_div">
      <form class="form-horizontal" role="form">
        <fieldset>
          <legend>
            <h3 id="user_enter"><b>用户登录入口</b></h3>
          </legend>
          <div class="form-group has-feedback">
            <label for="firstname" class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-6">
              <input type="text" class="form-control" id="username" placeholder="请输入用户名">
              <span class="form-control-feedback glyphicon glyphicon-user"></span>
            </div>
          </div>
          <div class="form-group has-feedback">
            <label for="lastname" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-6">
              <input type="text" class="form-control" id="password" placeholder="请输入密码">
              <span class="form-control-feedback glyphicon glyphicon-lock"></span>
            </div>
          </div>
          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <div class="checkbox">
                <label>
                  <input type="checkbox" id="me" checked="checked">请记住我
                </label>
              </div>
            </div>
          </div>
          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <button type="button" onclick="login()" class="btn btn-default">登录</button>
            </div>
          </div>
        </fieldset>
      </form>
    </div>
  </div>

  <!-- 登录end -->


  <!-- 必须先引入jquery.min.js -->
  <script src="../plugins/jquery.min.js"></script>
  <!-- 引入bootstrap.js -->
  <script src="../plugins/bootstrap-3.4.1-dist/js/bootstrap.js"></script>

  <script>
    $(function () {
      //当dom加载完毕之后,会自动执行此处的js代码.
      //从本地存储中获取username和pwd的值
      let uname = localStorage.getItem("username");
      let pwd = localStorage.getItem("pwd");

      //js写法
      document.getElementById("username").value = uname;
      //jquery写法
      $("#password").val(pwd);
    })

    function login() {
      //1. 判断记住密码是否选中
      let ck = document.getElementById("me");
      let username = document.getElementById("username").value;
      //jquery获取的方式
      let pwd = $("#password").val();
      if (ck.checked) {
        //h5里面的本地存储 - key和value的方式 - 都是一个字符串.
        localStorage.setItem("username", username);
        localStorage.setItem("pwd", pwd);
      } else {
        //清空本地缓存
        //localStorage.clear();
        localStorage.removeItem("username");
        localStorage.removeItem("pwd");
      }

      if (username == "skd" && pwd == "1951") {
        //TODO... 
        localStorage.setItem('carts', '{"admin":[]}');
        //跳转...
        window.location = "index.html";
      } else {
        alert('用户名或密码错误\n这都能忘了，你个小菜鸡(≖ ‿ ≖)✧');
      }
    }
  </script>
</body>

</html>